/** ***************************************************************************
 * CoffeeDefines.hpp
 * 2012 CoffeeParty Ltd.
 * Date Created: 2012-07-21                                  format YYYY-MM-DD
 * Revision Id: $Id$
 ******************************************************************************
 */

#ifndef _COFFEE_DEFINES_HPP_
#define _COFFEE_DEFINES_HPP_

#define rounding_i32    (0)
#define rounding_f32    (0.000001f)
#define rounding_f64    (0.00000001)

#define pi32            (3.14159265359f)
#define pi64            (3.1415926535897932384626433832795028841971693993751)

#define drop(_p)        { delete (_p); (_p) = NULL; }
#define rdrop(_p)       { delete[] (_p); (_p) = NULL; }

#define safe_drop(_p)   { if (_p) drop(_p); }
#define safe_rdrop(_p)  { if (_p) rdrop(_p); }

#define abs(_x)         ((_x < 0) ? -_x : _x)
#define fabs(_x)        ((_x < 0) ? -_x : _x)

#ifndef __WIN32
# define min(_x, _y)    ((_x < _y) ? _x : _y)
# define max(_x, _y)    ((_x < _y) ? _y : _x)
#endif

#define lowerform(_x)   ((_x >= 'A' && _x <= 'Z') ? _x + 0x20 : _x)
#define upperform(_x)   ((_x >= 'a' && _x <= 'z') ? _x + ('A' - 'a') : _x)

#define swap16(_x)      ((((_x) & 0xFF) << 8) | (((_x) & 0xFF00) >> 8))
#define swap32(_x)      ((((_x) & 0x000000FF) << 24) | (((_x) & 0xFF000000) >> 24) | (((_x) & 0x0000FF00) << 8) | (((_x) & 0x00FF0000) >> 8))

#define bswap16(_n)     (((_n) << 8 & 0xFF00) | ((_n) >> 8 & 0x00FF))
#define bswap32(_n)     ((bswap16(_n) << 16) | (bswap16(_n) >> 16))
#define bswap64(_n)     ((bswap32(_n) << 32) | (bswap32(_n) >> 32))

#define sof_array(_a)   (sizeof(_a) / sizeof((_a)[0]))

#ifndef NDEBUG
# include <assert.h>
# define try_to_break_if(_s) assert(!(_s))
#else
# define try_to_break_if(_s)
#endif

#endif /** _COFFEE_DEFINES_HPP_ */
